$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'sys/feedback/list',
        datatype: "json",
        colModel: [
            { label: 'ID', name: 'id', index: "id", width: 45, key: true },
            { label: '用户ID', name: 'userId', width: 75 },
            { label: '用户昵称', name: 'userName', width: 60},
            { label: '联系方式', name: 'contactWay', width: 60},
            { label: '类型', name: 'type', width: 60,formatter: function(value, options, row){
                    return value === 1 ?
                        '<span class="label label-danger">投诉</span>' :
                        '<span class="label label-success">建议</span>';
                }},
            { label: '反馈内容', name: 'content', width: 60},
            { label: '反馈时间', name: 'feedbackTime', width: 60},
            { label: '回复内容', name: 'reply', width: 60},
            { label: '回复时间', name: 'replayTime', width: 60},
            { label: '状态', name: 'status', width: 60, formatter: function(value, options, row){
                    return value === 1 ?
                        '<span class="label label-danger">待回复</span>' :
                        '<span class="label label-success">已回复</span>';
                }}
        ],
        viewrecords: true,
        height: 385,
        rowNum: 10,
        rowList : [10,30,50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page",
            rows:"limit",
            order: "order"
        },
        gridComplete:function(){
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });
});


var vm = new Vue({
    el:'#rrapp',
    data:{
        q:{
            userId: null,
            nickName: null,
            replayTime: null,
            replayTime1: null
        },
        showList: true,
        title:null,
        feedback:{

        }
    },
    methods: {
        query: function () {
            vm.reload();
        },
        update: function(event){
            var id = getSelectedRow();
            if(id == null){
                return ;
            }
            vm.showList = false;
            vm.title = "修改";
            vm.getFeedBack(id);
        },
        saveOrUpdate: function () {
            var url = "sys/feedback/update";
            $.ajax({
                type: "POST",
                url: baseURL + url,
                contentType: "application/json",
                data: JSON.stringify(vm.feedback),
                success: function(r){
                    if(r.code === 0){
                        alert('操作成功', function(){
                            vm.reload();
                        });
                    }else{
                        alert(r.msg);
                    }
                }
            });
        },
        getFeedBack: function(id){
            $.get(baseURL + "sys/feedback/info/"+id, function(r){
                vm.feedback = r.feedback;
            });
        },
        reload: function () {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam','page');
            $("#jqGrid").jqGrid('setGridParam',{
                postData:{
                    'userId':vm.q.userId,
                    'nickName':vm.q.nickName,
                    'replayTime':vm.q.replayTime,
                    'replayTime1':vm.q.replayTime1,},
                page:1
            }).trigger("reloadGrid");
        },
        exportExcel: function () {
            var url = "sys/feedback/exportExcel";
            var f = document.createElement("form");
            document.body.appendChild(f);
            var input = document.createElement("input");
            input.type = "hidden";
            f.appendChild(input);
            input.name = "param";
            input.value = JSON.stringify(vm.q);
            f.method="POST";
            f.action = baseURL + url;
            f.submit();
            f.remove();
        },
        reset:function(){
            vm.q = {userId:null, nickName:null, replayTime:null, replayTime1:null};
            $("input[name='qInput']").val('');
            vm.reload();

        }
    }

});
